package com.liangchen.astools.ui.notifications

import android.content.Intent
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.provider.Settings
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.TextView
import androidx.annotation.RequiresApi
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import com.liangchen.astools.R
import com.liangchen.astools.ui.floatwindow.FloatWindowService

class DebugFragment : Fragment() {
    private var notificationsViewModel: NotificationsViewModel? = null
    var btnTest: Button? = null
    @RequiresApi(Build.VERSION_CODES.M)
    override fun onCreateView(inflater: LayoutInflater,
                              container: ViewGroup?, savedInstanceState: Bundle?): View? {
        notificationsViewModel = ViewModelProvider(this).get(NotificationsViewModel::class.java)
        val root = inflater.inflate(R.layout.fragment_notifications, container, false)
        val textView = root.findViewById<TextView>(R.id.text_notifications)
        //notificationsViewModel.get().observe(viewLifecycleOwner, { s -> textView.text = s })
        btnTest = root.findViewById(R.id.btn_test)
        btnTest?.setOnClickListener(View.OnClickListener {
            if (!Settings.canDrawOverlays(context)) {
                startActivityForResult(Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + context?.packageName)), 0)
            } else {
                context?.startService(Intent(context, FloatWindowService::class.java))
            }
        })
        btnTest.hashCode()
        return root
    }
}